home *** CD-ROM | disk | FTP | other *** search
/ Univers Interactif 3 / INTERACTIF.BIN / mac / Planete.net / Internet Confirmés_Vrac / NetAgent.sea / src / div_func.c < prev    next >
Text File  |  1992-06-15  |  3KB  |  114 lines

  1. /*
  2. This is an unsupported product. It was developed as part of a study at Ostfold
  3. Regional College, Norway in the spring of 1992.
  4.  
  5. You use this software at your own risk. Neither the authors nor the Ostfold
  6. Regional College nor any other person or organization except yourself is
  7. responsible for any damage or loss of data derived from the use of this
  8. software. You may distribute this software freely as long as it is in its
  9. original form and all of its files are included. If you make any changes to any
  10. part of this software or the files distributed with it, please state so and do
  11. NOT distribute it under its original name.
  12. */
  13.  
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include <sys/types.h>
  17. #include <sys/socket.h>
  18. #include <netinet/in.h>
  19. #include <netdb.h>
  20. #include <fcntl.h>
  21.  
  22. /*
  23. -----------------------------------------------------------------------------
  24. Function name: les_linje()
  25. -----------------------------------------------------------------------------
  26. Parameters:    int fp        File identifier.
  27.         char *s        Buffer.
  28. Return value:    0 on error
  29.         1 on success
  30. Called by:    reg_user(), nytt(), new_news(), do_user(), finn_stikkord()
  31. Calls:        none
  32. Description:    Reads a line from the file fp and puts the line into the
  33.         buffer pointed to by s.
  34. -----------------------------------------------------------------------------
  35. */
  36.  
  37. int les_linje(fp, s)
  38. int fp;
  39. char *s;
  40. {
  41.     char kar, *linje;
  42.  
  43.     linje = s;
  44.  
  45.     while((read(fp, &kar, 1)) >0) {
  46.         if(kar == '\n') {
  47.             *s = '\0';
  48.             if(*linje == '\0')
  49.                 return(0);
  50.             else
  51.                 return(1);
  52.         }
  53.         *s = kar;
  54.         s++;
  55.     }
  56.     return(0);
  57. }
  58.  
  59. /*
  60. -----------------------------------------------------------------------------
  61. Function name: first_word()
  62. -----------------------------------------------------------------------------
  63. Parameters:    char *s        Pointer to a string.
  64. Return value:    none
  65. Called by:    finn_stikkord()
  66. Calls:        none
  67. Description:    Deletes the contains of a string except for the first word.
  68. -----------------------------------------------------------------------------
  69. */
  70.  
  71. void first_word(s)
  72. char *s;
  73. {
  74.     while((*s != 32) && (*s != '\0'))
  75.         s++;
  76.     *s = '\0';
  77. }
  78.  
  79. /*
  80. -----------------------------------------------------------------------------
  81. Function name: contains()
  82. -----------------------------------------------------------------------------
  83. Parameters:    char *s        Pointer to a string.
  84.         char *w        Pointer to a string.
  85. Return value:    Returns 0 on failure
  86.         Returns 1 on success
  87. Called by:    do_user()
  88. Calls:        none
  89. Description:    Checks to see wether s cointains w.
  90. -----------------------------------------------------------------------------
  91. */
  92.  
  93. int contains(s, w)
  94. char *s;
  95. char *w;
  96. {
  97.     char *ord;
  98.  
  99.     ord = w;
  100.  
  101.     while( *s != '\0') {
  102.         if( *w == '\0') {
  103.             return(1);
  104.         }
  105.         if( toupper((int) *s) == toupper((int) *w) )
  106.             w++;
  107.         else
  108.             w = ord;
  109.  
  110.         s++;
  111.     }
  112.     return(0);
  113. }
  114.